package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.WeekPlanProject;
import com.isunland.managesystem.utils.MyUtils;
import java.util.List;

/**
 * Created by wu on 2016/5/5.
 */
public class WeekPlanProjectAdapter extends ArrayAdapter<WeekPlanProject.Project> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2016-02-17 11:00:00 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final TextView tvDataPublicAnnounce;
    public final TextView tvPersonPublicAnnounce;
    public final TextView tvDatePublicAnnounce;
    public final TextView tvDataStatusPublicAnnounce;
    public final TextView tvDataAnnounce;
    public final TextView tvPersonAnnounce;
    public final TextView tvTimeAnnounce;

    private ViewHolder(LinearLayout rootView, TextView tvDataPublicAnnounce,
        TextView tvPersonPublicAnnounce, TextView tvDatePublicAnnounce,
        TextView tvDataStatusPublicAnnounce, TextView tvDataAnnounce, TextView tvPersonAnnounce,
        TextView tvTimeAnnounce) {
      this.rootView = rootView;
      this.tvDataPublicAnnounce = tvDataPublicAnnounce;
      this.tvPersonPublicAnnounce = tvPersonPublicAnnounce;
      this.tvDatePublicAnnounce = tvDatePublicAnnounce;
      this.tvDataStatusPublicAnnounce = tvDataStatusPublicAnnounce;
      this.tvDataAnnounce = tvDataAnnounce;
      this.tvPersonAnnounce = tvPersonAnnounce;
      this.tvTimeAnnounce = tvTimeAnnounce;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvDataPublicAnnounce = (TextView) rootView.findViewById(R.id.tv_data_publicAnnounce);
      TextView tvPersonPublicAnnounce =
          (TextView) rootView.findViewById(R.id.tv_person_publicAnnounce);
      TextView tvDatePublicAnnounce = (TextView) rootView.findViewById(R.id.tv_date_publicAnnounce);
      TextView tvDataStatusPublicAnnounce =
          (TextView) rootView.findViewById(R.id.tv_dataStatus_publicAnnounce);
      TextView tvDataAnnounce = (TextView) rootView.findViewById(R.id.tv_data_Announce);
      TextView tvPersonAnnounce = (TextView) rootView.findViewById(R.id.tv_person_Announce);
      TextView tvTimeAnnounce = (TextView) rootView.findViewById(R.id.tv_time_Announce);
      return new ViewHolder(rootView, tvDataPublicAnnounce, tvPersonPublicAnnounce,
          tvDatePublicAnnounce, tvDataStatusPublicAnnounce, tvDataAnnounce, tvPersonAnnounce,
          tvTimeAnnounce);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_workrequest_announce_list, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    WeekPlanProject.Project item = getItem(position);
    vh.tvDataAnnounce.setText(R.string.weekProjectName);
    vh.tvPersonAnnounce.setText(R.string.customerNameDelivery);
    vh.tvTimeAnnounce.setText(R.string.registerTimeAnnounce);

    vh.tvDataPublicAnnounce.setText(item.getProjectName());
    vh.tvDataPublicAnnounce.setTextColor(getContext().getResources().getColor(R.color.blue_click));
    vh.tvPersonPublicAnnounce.setText(item.getPartaName());
    vh.tvDatePublicAnnounce.setText(item.getRegDate());
    MyUtils.switchDataStutus(getContext(), vh.tvDataStatusPublicAnnounce, item.getDataStatus());
    return vh.rootView;
  }

  private LayoutInflater mInflater;

  // Constructors
  public WeekPlanProjectAdapter(Context context, List<WeekPlanProject.Project> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  public WeekPlanProjectAdapter(Context context, WeekPlanProject.Project[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }
}
